package com.suse.warmstill.controller;

import com.alibaba.fastjson.JSONObject;
import com.suse.warmstill.common.model.CallResult;
import com.suse.warmstill.common.utils.UserIdThreadLocal;
import com.suse.warmstill.service.ChatMsgService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.messaging.handler.annotation.DestinationVariable;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.messaging.simp.annotation.SubscribeMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author 黄靖
 * @author 2023-02-12 06:45
 * description:
 **/
@RestController
@Slf4j
@Api(tags = "聊天---》websocket 连接")
@RequestMapping("/websocket")
public class ConnectionApi {


    @Resource
    private ChatMsgService msgService;

    /**
     * 1.用户登录的时候，通过SimpMessagingTemplate给对应的房间发送用户信息，
     * 当前用户没有订阅该频道，是接收不到信息的
     * 2.用户订阅该频道，要给房间内的所有用户发送用户列表信息
     */
    @ApiOperation("连接后返回聊天用户的 信息")
    //  @SubscribeMapping("/connect/{acceptId}/{senderId}")
    @GetMapping("/connect/{accepterId}/{senderId}")
    public CallResult connect(@PathVariable("accepterId") int accepterId,
                              @PathVariable("senderId") int senderId
    ) {
        System.out.println("请求道理的");
        return msgService.connect(accepterId, senderId);
        // 统一发送消息

    }

}
